package com.jh.pattern.singleton.broke;

import com.jh.pattern.singleton.lazy.LazyInnerClassSingleton;
import com.jh.pattern.singleton.register.EnumSingleton;

import java.lang.reflect.Constructor;

/**
 * @author JH_Wong
 * @projectName newforward
 * @title ReflectionSingleton.java
 * @package com.jh.pattern.brokesingleton
 * @description 反射破坏单例
 * @date 2019-05-23 10:00
 */
public class ReflectionSingleton {
    public static void main(String[] args) throws Exception {
        //Class<?> clazz = LazyInnerClassSingleton.class;
        Class<?> clazz = EnumSingleton.class;
        Constructor<?> constructor = clazz.getDeclaredConstructor(null);
        constructor.setAccessible(true);
        Object obj1 = constructor.newInstance();
        Object obj2 = constructor.newInstance();
        System.out.println(obj1);
        System.out.println(obj2);
        System.out.println(obj1 == obj2);
    }
}
